<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of MenuElement
 *
 * @author aneto
 */
abstract class MenuElement extends ArrayObject {
	
	protected $id;
	protected $name;
	protected $link;
	protected $fetchedData;

	protected $parentMenuElement;

	const PRODUCT_GROUP = 1;
	const STRUCTURE_NODE = 2;

	abstract function getSubElements();
	abstract function isHidden();
	abstract function isActive();
	abstract function hasChildren();
	abstract function getType();
	abstract function getParameter($parameter = 'parameter');

	public function __construct(array $fetchedData, NavigationMenu $menu, MenuElement $parent = null){

		$this->setFetchedData($fetchedData);
		$this->setMenu($menu);
		if($parent)
			$this->setParentMenuElement($parent);

	}
	
	protected function setMenu(NavigationMenu $nm){
		$this->menu = $nm;
	}

	protected function setFetchedData(array $fetchedData){
		$this->fetchedData = $fetchedData;
	}

	
	protected function setParentMenuElement(MenuElement $me){
		$this->parentMenuElement = $me;
	}


	public function getParentMenuElement(){
		return $this->parentMenuElement;
	}




	public function getLink(){
		return $this->link;
	}

	public function getName(){
		return $this->name;
	}

	public function getFetchedData(){
		return $this->fetchedData;
	}

	public function getId(){
		return $this->id;
	}
	
	protected function getMenu(){
		return $this->menu;
	}




	public function  __toString() {
		return 'name: ' . $this->getName() . '\n';
	}

	static function getInstance(array $data, $type, NavigationMenu $e,  MenuElement $me = null){

		switch($type){
			case self::STRUCTURE_NODE:
				return new StructureMenuElement($data, $e, $me);
				break;
			case self::PRODUCT_GROUP:
				return new ProductGroupMenuElement($data, $e, $me);
				break;
			default:
				throw new Exception('invalid type of menu element');
		}
	}


}
?>
